//*- coding = utf-8 -*-
//@Time : 2023-11-19 15:50
//@Author : 管茂良
//@File : setting.js
//@web  : www.php-china.com
//@Software: WebStorm

import {defineStore} from "pinia";
import storeName from "@/store/storeName";
import config from "@/utils/config"
import {getLayoutSetting} from "@/utils/storage"

let {Language,Theme,FontSize} = config
const storageSetting:any = getLayoutSetting()

const useSettingStore = defineStore(storeName.setting,{
    state:()=>({
        language: storageSetting?.language === undefined ? Language : storageSetting?.language,
        themeColor:storageSetting?.themeColor === undefined ? Theme : storageSetting?.themeColor,
        fontSize:storageSetting?.fontSize === undefined ? FontSize : storageSetting?.fontSize,
    }),
    getters:{
        getter(state?:string|number|object):any{
            return state
        }
    },
    actions:{
        //动态修改状态管理state值
        handleChangeSetting(data:{ key:string|number|Array<any>, value:any }) {
            if(data.key instanceof Array){
                if(this.getter.hasOwnProperty(data.key[0])){
                    this.getter[data.key[0]][data.key[1]] = data.value
                }
            }else{
                if(this.getter.hasOwnProperty(data.key)){
                    this.getter[data.key] = data.value
                }
            }
        }
    }
})

export default useSettingStore